const minBuyQty = (minBuyQty,minBuyNum) => {
	if(minBuyQty > minBuyNum){
		return minBuyQty
	} else {
		return minBuyNum
	}
}
const maxBuyQty = (goodsStorage,maxBuyNum) => {
	if(maxBuyNum > 0 && maxBuyNum < goodsStorage){
		return maxBuyNum
	} else {
		return goodsStorage
	}
}

// 商品价格、库存、起购数量控制
export const goodsContorl = (goods) => {
	let activityList = goods.activityList || []
	switch (activityList.length) {
		case 0:
		goods.maxBuyQty = maxBuyQty(goods.goodsStorage)
		return goods;
		default:
			switch (activityList[0].activityType){
				case 0:
				goods.activityType = activityList[0].activityType;
				goods.activityId = activityList[0].id;
				goods.activityTypeName = '特价';
				goods.goodsPrice = activityList[0].ruleType==0? activityList[0].activityObject.activityPrice:(goods.goodsPrice*parseFloat(activityList[0].activityObject.discountRate)).toFixed(2)
				goods.maxBuyQty = maxBuyQty(goods.goodsStorage, activityList[0].activityObject.maxBuyNum)
				goods.minBuyQty = minBuyQty(goods.minBuyQty, activityList[0].activityObject.minBuyNum)
				goods.activityList[0].activityTypeRuleDescripetion = ''
				return goods;
				case 10:
				goods.activityType = activityList[0].activityType;
				goods.activityId = activityList[0].id;
				goods.activityTypeName = '满减';
				goods.activityList[0].activityTypeRuleDescripetion = ''
				activityList[0].activityRuleList.forEach((ruleItem,ruleIndex)=>{
					goods.activityList[0].activityTypeRuleDescripetion += `满${parseFloat(ruleItem.limitWhere)}元，立减${parseFloat(ruleItem.couponAmount)}元；`
				})
				goods.maxBuyQty = maxBuyQty(goods.goodsStorage, activityList[0].activityObject.maxBuyNum)
				goods.minBuyQty = minBuyQty(goods.minBuyQty, activityList[0].activityObject.minBuyNum)
				return goods;
				case 30:
				goods.activityType = activityList[0].activityType;
				goods.activityId = activityList[0].id;
				goods.activityTypeName = '满赠';
				goods.activityList[0].activityTypeRuleDescripetion = ''
				activityList[0].activityRuleList.forEach((ruleItem,ruleIndex)=>{
					goods.activityList[0].activityTypeRuleDescripetion += `${ruleItem.ruleName}；`
				})
				goods.maxBuyQty = maxBuyQty(goods.goodsStorage, activityList[0].activityObject.maxBuyNum)
				goods.minBuyQty = minBuyQty(goods.minBuyQty, activityList[0].activityObject.minBuyNum)
				return goods;
			}
	}
}

// 活动类型名称
export const activityTypeName = (type) => {
	switch (type){
		case 0:
		return '特价';
		case 10:
		return '满减';
		case 30:
		return '满赠';
	}
}

// 满足活动描述
export const actCartDescription = (obj) => {
	console.log(obj)
	switch (obj.type){
		case 10:
		return (obj.nowActivity?`已减${obj.nowActivity.couponAmount}元；`:'' )+(obj.willActivity&&obj.willActivity.limitWhere?`再买${obj.willActivity.limitWhere-obj.nowActivityMon}元可减${obj.willActivity.couponAmount}元`:'');
		case 30:
		return (obj.nowActivity && obj.nowActivity.giftList?`赠${
			obj.nowActivity.giftList.map((item,index)=>{
				return item.giftName+item.qty+item.giftUnit + (index<obj.nowActivity.giftList.length-1?',':'')
			})
		}；`:'')+(obj.willActivity && obj.willActivity.giftList?`再买${obj.willActivity.limitWhere-obj.nowActivityMon}元可赠${
			obj.willActivity.giftList.map((item,index)=>{
				return item.giftName+item.qty+item.giftUnit + (index<obj.willActivity.giftList.length-1?',':'')
			})
		}`:'');
	}
}